//由于kerwin写路由的方法是使用的react-router-dom v5 所以我们使用react-router-dom v6的写法 使用router组件和RouterProvider组件来挂载路由
import { createHashRouter } from "react-router-dom";
import Login from "../view/Login";
import NewSandBox from "../view/NewSandBox";
import PrivateRouter from "../components/PrivateRouter";
import Home from "../view/Home/Home";
import UserList from "../view/NewSandBox/User-manage/UserList";
import RoleList from "../view/NewSandBox/Role-manage/RoleList";
import RightList from "../view/NewSandBox/Right-manage/RightList";
import Draft from "../view/NewSandBox/news-manage/Draft";
import Category from "../view/NewSandBox/news-manage/Category";
import NotFund from "../view/404/404";
import { Navigate } from "react-router-dom";
import Published from "../view/NewSandBox/publish-manage/Published";
import Unpublished from "../view/NewSandBox/publish-manage/Unpublished";
import Sunset from "../view/NewSandBox/publish-manage/Sunset";
import NewsPreview from "../view/NewSandBox/news-manage/NewsPreview";
import Audit from "../view/NewSandBox/audit-manage/Audit";
import AuditList from "../view/NewSandBox/audit-manage/AuditList";
import NewsAdd from "../view/NewSandBox/news-manage/NewsAdd";
import NewsUpdate from "../view/NewSandBox/news-manage/NewsUpdate";
import News from "../view/news/News";
import Detail from "../view/news/Detail";
//使用createHashRouter创建路由
const router = createHashRouter([
  {
    //用户登录
    path: "/login",
    element: <Login />,
  },
  {
    // 用户业务
    path: "/",
    element: (
      <PrivateRouter>
        <NewSandBox />
      </PrivateRouter>
    ), //如果未授权 就会重定向到login页面 需要使用路由守卫 PrivateRouter 来包裹NewSandBox组件 ，
    children: [
      {
        //home组件
        path: "home",
        element: <Home />,
      },
      {
        //用户列表组件
        path: "user-manage/list",
        element: <UserList />,
      },
      {
        //角色列表组件
        path: "right-manage/role/list",
        element: <RoleList />,
      },
      {
        //权限列表组件
        path: "right-manage/right/list",
        element: <RightList />,
      },
      {
        path: "/404",
        element: <NotFund />,
      },
      {
        path: "/news-manage/add",
        element: <NewsAdd />, //*
      },
      {
        path: "/news-manage/preview/:id",
        element: <NewsPreview />, //*
      },
      {
        path: "/news-manage/draft",
        element: <Draft />,
      },
      {
        path: "/news-manage/update/:id",
        element: <NewsUpdate />,
      }
      ,
      {
        path: "/news-manage/category",
        element: <Category />,
      },
      {
        path: "/audit-manage/audit",
        element: <Audit />,
      },
      {
        path: "/audit-manage/list",
        element: <AuditList />,
      },
      {
        path: "/publish-manage/unpublished",
        element: <Unpublished />,
      },
      {
        path: "/publish-manage/published",
        element: <Published />,
      },
      {
        path: "/publish-manage/sunset",
        element: <Sunset />,
      },
      //重定向
      {
        path: "/",
        element: <Navigate to="/home" />,
      },
      {
        path: "*",
        element: <Navigate to="/404" />,
      },
    ],
  },
  {
    //游客浏览
    path:'/news',
    element:<News/>
  },
  {
    path:'/detail/:id',
    element:<Detail/>
  }
]);

export default router;
